﻿using System;
using System.Collections.Generic;

namespace TestsBase.lib
{
    public class TestDatabase
    {
        private int _CurrentIndex;
        private int _MaxTests;
        private string _Name;
        private List<Test> _Tests;

        public TestDatabase()
        {
        }

        public TestDatabase(string Name, int MaxTests)
        {
            _MaxTests = MaxTests;
            _Name = Name;
            _Tests = new List<Test>();
            _CurrentIndex = 0;
        }

        public int MaxTests
        {
            get { return _MaxTests; }
        }

        public List<Test> Tests
        {
            get { return _Tests; }
        }

        public string Name
        {
            get { return _Name; }
        }

        public int Position
        {
            get { return _CurrentIndex; }
        }

        public Test SelectedTest
        {
            get
            {
                if (_Tests[_CurrentIndex] == null) throw new Exception("Selected Test not exists");
                return _Tests[_CurrentIndex];
            }
        }

        public bool First()
        {
            _CurrentIndex = 0;
            return true;
        }

        public bool Prev()
        {
            if (_CurrentIndex < 1) return false;
            if (_Tests[_CurrentIndex - 1] == null) return false;
            _CurrentIndex--;
            return true;
        }

        public bool Next()
        {
            if (_CurrentIndex > _MaxTests - 1) return false;
            if (_Tests.Count <= _CurrentIndex + 1) return false;
            _CurrentIndex++;
            return true;
        }
    }
}